package com.jiantong.work.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import io.terminus.common.utils.JsonMapper;
import lombok.Data;
import lombok.Getter;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * Created by Administrator on 2017/3/28.
 */
@Data
public class DisinfectReport implements Serializable{
    private static final ObjectMapper objectMapper= JsonMapper.nonEmptyMapper().getMapper();
    private static final long serialVersionUID = -2933114922051954107L;

    /**
     * id
     */
    private Long id;
    /**
     * 单据编号
     */
    private String number;
    /**
     * 养殖场id
     */
    private Long breedFactoryId;
    /**
     * 养殖场名称
     */
    private String  breedFactoryName;
    /**
     * 消毒人员
     */
    private String operator;
    /**
     * 记录日期
     */
    private Date date;
    /**
     *养殖场区域
     */
    private Integer area;

    /**
     * 栏舍号id
     */
    private Long stableId;

    /**
     *栏舍号
     */
    private String stableNumber;
    /**
     *动物种类
     */
    private Integer productType;
    /**
     *单位
     */
    private Integer unit;
    /**
     *消毒方法
     */
    private Integer disinfectMethod;
    /**
     *其它消毒方法
     */
    private String otherMethod;
    /**
     * 消毒范围
     */
    private String disinfectRange;
    /**
     * 消毒面积
     */
    private String disinfectArea;
    /**
     *用药名称
     */
    private String drugName;
    /**
     *用药量
     */
    private Float drugUsedQuantity;
    /**
     * 稀释比例
     */
    private String dilutionRate;
    /**
     *用量单位，1...2...
     */
    private Integer drugUsedUnit;
    /**
     *兽药照片
     */
    @JsonIgnore
    private String drugPhoto;
    /**
     * 兽药照片-----不存入数据库
     */
    @Getter
    private Map<String,Map<String,String>> drug;
    /**
     *备注
     */
    private String remark;
    /**
     *状态，0：正常，1：删除
     */
    private Integer status;
    /**
     *'1：正常，-1：删除'
     */
    private Integer deleteFlag;
    /**
     *
     */
    private Date createdAt;
    /**
     *
     */
    private Date updatedAt;


    public void setDrugPhoto(String drugPhoto) throws Exception{
        this.drugPhoto = drugPhoto;
        if(Strings.isNullOrEmpty(drugPhoto)){
            this.drug=  Maps.newHashMap();
        } else{
            this.drug = objectMapper.readValue(drugPhoto, new TypeReference<Map<String,Map<String,String>>>(){});
        }
    }
    public void setDrug(Map<String,Map<String,String>> drug) {
        this.drug = drug;
        if(drug ==null ||drug.isEmpty()){
            this.drugPhoto = null;
        }else{
            try {
                this.drugPhoto = objectMapper.writeValueAsString(drug);
            } catch (Exception e) {
            }
        }
    }
}
